TOOL.Category		= "(WarMelons)"
TOOL.Name			= "#NRG Donator"
TOOL.Command		= nil
TOOL.ConfigName		= ""

TOOL.ClientConVar[ "totalnrg" ] = "0"
TOOL.ClientConVar[ "name" ] = ""
TOOL.ClientConVar[ "playa" ] = "1"
if (CLIENT) then
	language.Add( "Tool_lap_donator_name", "NRG Donator" )
	language.Add( "Tool_lap_donator_desc", "Gives NRG to other players" )
	language.Add( "Tool_lap_donator_0", "Left-click to modify a player's NRG by ID. Right-click to give named player NRG." )
end

function TOOL:LeftClick (trace)
if (SERVER) then
		local pl = self:GetOwner()
		local ply = self:GetClientNumber("playa")
		local tnrg = self:GetClientNumber("totalnrg")
		if player.GetByID(ply):IsValid() then
			if pl:GetNetworkedInt("nrg") >= tnrg then
			player.GetByID(ply):SetNetworkedInt( "nrg" , player.GetByID(ply):GetNetworkedInt( "nrg" ) + tnrg)
			pl:SetNetworkedInt("nrg", pl:GetNetworkedInt("nrg") - tnrg)
			local message = "You gave " .. player.GetByID(ply):GetName() .. " " .. tnrg .. " NRG."
			pl:PrintMessage( HUD_PRINTTALK, message )
			message = pl:GetName() .. " gave you " .. tnrg .. " NRG."
			pl:PrintMessage( HUD_PRINTTALK, message )
			else
			pl:PrintMessage( HUD_PRINTTALK, "You do not have enough NRG" )
			end
		else
		pl:PrintMessage( HUD_PRINTTALK, "That is not a valid player ID" )
		end
end
end



function TOOL:RightClick (trace)
if (SERVER) then
		local pl = self:GetOwner()
		local ply = self:GetOwner()
		local tnrg = self:GetClientNumber("totalnrg")
		 for k, v in pairs(player.GetAll()) do
			if v:GetName() == self:GetClientInfo("name") then
			ply = v
			end
		 end
		if ply ~= self:GetOwner() then
			if pl:GetNetworkedInt("nrg") >= tnrg then
			ply:SetNetworkedInt( "nrg" , ply:GetNetworkedInt( "nrg" ) + tnrg)
			pl:SetNetworkedInt("nrg", pl:GetNetworkedInt("nrg") - tnrg)
			local message = "You gave " .. ply:GetName() .. " " .. tnrg .. " NRG."
			pl:PrintMessage( HUD_PRINTTALK, message )
			message = pl:GetName() .. " gave you " .. tnrg .. " NRG."
			ply:PrintMessage( HUD_PRINTTALK, message )
			else
			pl:PrintMessage( HUD_PRINTTALK, "You do not have that much NRG" )
			end
		else
		pl:PrintMessage( HUD_PRINTTALK, "Player not found" )
		end
end
end

function TOOL.BuildCPanel (CPanel)
	CPanel:AddControl ("Header", { Text="#Tool_lap_donator_name", Description="#Tool_lap_donator_desc" })
	CPanel:AddControl ("Slider", {
		Label = "PlayerID",
		Command = "lap_donator_playa",
		Type = "Integer",
		Min = "1",
		Max = "32"
	} )
	CPanel:AddControl ("Slider", {
		Label = "NRG",
		Command = "lap_donator_totalnrg",
		Type = "Integer",
		Min = "0",
		Max = "100000"
	} )
	CPanel:AddControl ("TextBox", {
		Label = "Name",
		Command = "lap_donator_name",
		Type = "String"
	} )
end
